package com.android.fastride.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.fastride.R;
import com.android.fastride.contract.MessageDetailContract;
import com.android.fastride.model.db.entity.FastRideMessage;
import com.android.fastride.present.MessageDetailPresent;
import com.android.fastride.view.widget.TopBar;
import com.peng.library.mantis.expand.data.MantisDataFragment;
import com.peng.library.mantis.hint.HintConfig;
import com.peng.library.mantis.mvp.BindPresent;

import java.util.Calendar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

@BindPresent(MessageDetailPresent.class)
public class MessageDetailFragment extends MantisDataFragment<MessageDetailContract.PRESENT,
        FastRideMessage.NoticeBean> implements
        MessageDetailContract
                .VIEW {

    public static String PARA = "para";

    Unbinder unbinder;
    @BindView(R.id.topBar)
    TopBar topBar;
    @BindView(R.id.tv_message_title)
    TextView tvMessageTitle;
    @BindView(R.id.tv_message_time)
    TextView tvMessageTime;
    @BindView(R.id.tv_message_content)
    TextView tvMessageContent;

    private FastRideMessage.NoticeBean mNoticeBean ;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
            Bundle savedInstanceState, HintConfig.Builder hintConfigBuilder) {
        Bundle bundle = getArguments();
        mNoticeBean = (FastRideMessage.NoticeBean)bundle.getSerializable(PARA);
        View view = inflater.inflate(R.layout.fragment_message_detail, container, false);
        unbinder = ButterKnife.bind(this, view);
        topBar.setOnLeftAndRightClickListener(new TopBar.OnLeftAndRightClickListener() {
            @Override
            public void OnLeftButtonClick() {
                getActivity().finish();
            }

            @Override
            public void OnRightButtonClick() {

            }
        });
        if (bundle != null) {
            tvMessageTitle.setText(mNoticeBean.getTitle());
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(mNoticeBean.getCreatedAt());
            tvMessageTime.setText(calendar.get(Calendar.YEAR) + "-"
                    + calendar.get(Calendar.MONTH) + "-"
                    + calendar.get(Calendar.DAY_OF_MONTH));
            tvMessageContent.setText(mNoticeBean.getContent());
        } else {
            getViewDelegate().showEmptyView();
        }
        return view;
    }

    @Override
    public void onReceiveData(FastRideMessage.NoticeBean noticeBean) {

    }

    @Override
    public void onReceiveError(Throwable throwable) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
}
